package com.jeasonzhao.report.dataset;

import com.jeasonzhao.report.codes.DataSetCellTypes;

public class RowInfo extends java.util.Vector<DataCell>
{
    private static final long serialVersionUID = 1L;
    private int m_nRowIndex = 0;
    private DataSetCellTypes m_rowType = DataSetCellTypes.Normal;
    private Object m_objTag;
    private String m_strExtraText;
    private String m_strRowTreeIndex = null;
    private String m_strRowTreeParentIndex = null;
    public RowInfo()
    {
        super();
    }
    public int hashCode()
    {
    	return super.hashCode();
    }
    public boolean equals(Object obj)
    {
    	return super.equals(obj);
    }
    public void setTreeNodeIndex(String strParentNodeIndex,String strTreeNodeIndex)
    {
        m_strRowTreeParentIndex = strParentNodeIndex;
        m_strRowTreeIndex = strTreeNodeIndex;
    }

    public String getParentTreeNodeIndex()
    {
        return m_strRowTreeParentIndex;
    }

    public String getTreeNodeIndex()
    {
        return m_strRowTreeIndex;
    }

    public RowInfo(int nSize)
    {
        for(int n = 0;n < nSize;n++)
        {
            this.add(new DataCell());
        }
    }

    public RowInfo(RowInfo row)
    {
        this(row,false,false);
    }

    public RowInfo(RowInfo row,boolean isCleanColRowSpan,boolean isHide)
    {
        if(null == row)
        {
            return;
        }
        for(int n = 0;n < row.size();n++)
        {
            DataCell cell = new DataCell(row.get(n));
            if(isCleanColRowSpan)
            {
                cell.setRowSpan( -1);
                cell.setColSpan( -1);
            }
            if(isHide)
            {
                cell.setVisiable(false);
            }
            this.add(cell);
        }
        this.m_nRowIndex = row.m_nRowIndex;
        this.m_rowType = row.m_rowType;
//        this.m_nShrikRowsCount=row.m_nShrikRowsCount;
    }

    public DataSetCellTypes getRowType()
    {
        return null == m_rowType ? DataSetCellTypes.Normal : m_rowType;
    }

    public void setRowType(DataSetCellTypes value)
    {
        m_rowType = value;
        for(int n = 0;n < this.size();n++)
        {
            DataCell cell = this.get(n);
            if(null != cell)
            {
                cell.setCellType(value);
            }
        }
    }

    public int getRowIndex()
    {
        return m_nRowIndex;
    }

    public void setRowIndex(int rowIndex)
    {
        this.m_nRowIndex = rowIndex;
    }

    public static RowInfo fromArray(DataCell[] arys)
    {
        if(null == arys)
        {
            return null;
        }
        RowInfo ret = new RowInfo();
        for(int n = 0;n < arys.length;n++)
        {
            ret.addElement(arys[n]);
        }
        return ret;
    }

    public static RowInfo createSpanedRow(Object obj,int nColSpan)
    {
        RowInfo ret = new RowInfo();
        for(int n = 0;n < nColSpan;n++)
        {
            ret.addElement(DataCell.create(obj));
            ret.get(n).setVisiable(n == 0);
        }
        ret.get(0).setColSpan(nColSpan);
        return ret;
    }

    public static RowInfo fromArrayValues(Object[] values)
    {
        if(null == values)
        {
            return null;
        }
        RowInfo ret = new RowInfo();
        for(int n = 0;n < values.length;n++)
        {
            ret.addElement(DataCell.create(values[n]));
        }
        return ret;
    }

    public static RowInfo fromArrayValues(double[] values)
    {
        if(null == values)
        {
            return null;
        }
        RowInfo ret = new RowInfo();
        for(int n = 0;n < values.length;n++)
        {
            ret.addElement(DataCell.create(new Double(values[n])));
        }
        return ret;
    }

    public static RowInfo fromArrayValues(int[] values)
    {
        if(null == values)
        {
            return null;
        }
        RowInfo ret = new RowInfo();
        for(int n = 0;n < values.length;n++)
        {
            ret.addElement(DataCell.create(Integer.valueOf(values[n])));
        }
        return ret;
    }

    public static RowInfo fromArrayValues(float[] values)
    {
        if(null == values)
        {
            return null;
        }
        RowInfo ret = new RowInfo();
        for(int n = 0;n < values.length;n++)
        {
            ret.addElement(DataCell.create(new Double(values[n])));
        }
        return ret;
    }

    public static RowInfo fromList(java.util.List<DataCell> list)
    {
        if(null == list)
        {
            return null;
        }
        RowInfo ret = new RowInfo();
        for(int n = 0;n < list.size();n++)
        {
            ret.addElement((DataCell) list.get(n)); //may cause a cast-exception.
        }
        return ret;
    }

    public void compress()
    {
        for(int n = 0;n <= this.size();n++)
        {
            if(this.elementAt(n) == null)
            {
                this.remove(n);
                n--;
            }
        }
    }

    public void insertElementAfter(DataCell value,int nIndex)
    {
        nIndex++;
        if(nIndex < size())
        {
            this.insertElementAt(value,nIndex);
        }
        else
        {
        	this.add(value);
        }
    }
    public DataCell[] toArray()
    {
        DataCell[] ret = new DataCell[this.size()];
        this.copyInto(ret);
        return ret;
    }

    public void sort(java.util.Comparator<Object> comp)
    {
        if(null == comp || this.size() < 1)
        {
            return;
        }
        DataCell[] items = this.toArray();
        java.util.Arrays.sort(items,comp);
        this.clear();
        for(int n = 0;n < items.length;n++)
        {
            this.addElement(items[n]);
        }
    }

    public String toString()
    {
        return toString("",false);
    }

    public String toString(String str,boolean appendAtFirst)
    {
        StringBuffer strRet = new StringBuffer();
        for(int n = 0;n < this.size();n++)
        {
            if(null != str && (n > 0 || appendAtFirst))
            {
                strRet.append(str);
            }
            strRet.append(this.elementAt(n));
        }
        return strRet.toString();
    }

    public void setTag(Object tag)
    {
        this.m_objTag = tag;
    }

    public void setExtraText(String extraText)
    {
        this.m_strExtraText = extraText;
    }

    public Object getTag()
    {
        return m_objTag;
    }

    public String getExtraText()
    {
        return m_strExtraText;
    }

    public void setVisiable(boolean b)
    {
        for(int n = 0;n < this.size();n++)
        {
            this.get(n).setVisiable(b);
        }
    }
}
